<?php

class Misc {

    public static function dateFormat($date) {
        if ($date) {
            $date = new DateTime($date);

            return $date->format('d/m/Y H:i:s');
        } else {
            return '-';
        }
    }

    public static function isLogged() {
        Zend_Loader::loadClass('Zend_Auth');
        $authClass = Zend_Auth::getInstance();

        return $authClass->hasIdentity();
    }

    public static function isAdmin() {
        $usuario = self::getLoggetUser();

        return $usuario['tipo'] == 'administrador';
    }

    public static function getLoggetUser() {
        if (Misc::isLogged()) {
            $id = Misc::getLoggetUserId();

            $usuarioModel = new Application_Model_Usuario();

            $usuario = $usuarioModel->find($id)->current();

            return $usuario;
        }

        return null;
    }

    public static function getLoggetUserId() {
        Zend_Loader::loadClass('Zend_Auth');
        $authClass = Zend_Auth::getInstance();

        if ($authClass->hasIdentity()) {
            $auth = $authClass->getStorage()->read();

            return $auth['usuario_id'];
        }

        return null;
    }

}

?>